#include "load.h"

unsigned char* loadBMPHeaderAndHuffman(BMP *bmp,FILE *input,int *size){

	fread(&bmp->fileHeader,sizeof(BMP_FILE_HEADER),1,input);
	fread(&bmp->bmpHeader,sizeof(BMP_BITMAP_HEADER),1,input);
	

	FREQUENCY_SAVE f;
	readHuffmanFrequency(input,f);
	
	int size_bytes;
	fread(&size_bytes,sizeof(int),1,input);
	
	unsigned char *bytes = (unsigned char *)malloc(sizeof(unsigned char)*(size_bytes+1));
	
	int x = fread(bytes,sizeof(unsigned char),size_bytes+1,input);
	 while( x < size_bytes)
        x += fread(bytes+x,sizeof(unsigned char),size_bytes-x,input);

#ifdef DEBUG
	printf("size_bytes: %d\n",size_bytes);		
	printBMPFileHeader(bmp);

	int i=0;
	for(;i<size_bytes;i++)
		printf("%d, %x, %d\n",i,bytes[i],bytes[i]);
#endif

	*size = size_bytes;
	return bytes;
}


